package com.jadows.tdog.message.handler.pipline.impl;

import com.jadows.tdog.domain.ChatMessage;
import com.jadows.tdog.message.handler.pipline.IMessagePipeline;
import com.jadows.tdog.message.handler.pipline.IMessageProcess;
import io.netty.channel.Channel;

import java.util.LinkedList;
import java.util.List;

/**
 * @author taojiacheng
 */
public class DefaultMessagePipeline implements IMessagePipeline {

    final List<IMessageProcess> processes = new LinkedList<>();

    @Override
    public IMessagePipeline addLast(IMessageProcess handler) {
        processes.add(handler);
        return this;
    }

    @Override
    public void process(ChatMessage message, Channel channel) {
        for (IMessageProcess process : processes) {
            message = process.handlerMessage(message, channel);
        }
    }
}
